package org.chispa.api.parsers;

import java.util.NoSuchElementException;
import java.util.Scanner;

import org.chispa.api.parsers.StateRepository.State;
import org.chispa.api.util.BadSyntaxException;
import org.chispa.api.util.ExpressionLanguage;
import org.chispa.api.util.NoSuitableVisitorException;

class InitialParserState extends ParserState {

	protected InitialParserState(Scanner scan,StringBuilder buff) {
		super(scan,buff);
	}
	
	protected InitialParserState(Scanner scan) {
		super(scan);
	}

	@Override
	protected ParserState validateState(String text) throws NoSuchElementException, BadSyntaxException, NoSuitableVisitorException {
		if(isUnclosedLiteral(text))
		{
			ParserState state=repo.getStateFor(State.LITERAL, this);
			return state.validateState(text);
		}
		if(ExpressionLanguage.matchesHash(text))
		{
			return repo.getStateFor(State.HASH, this).validateState(text);
		}
		if(ExpressionLanguage.matchesEncr(text))
		{
			return repo.getStateFor(State.ENCRYPTION, this).validateState(text);
		}
		append(text);
		return this.validateState();
	}

}